package br.com.syshealth.clinica.session;

import java.util.List;
import java.util.Set;


import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.hibernate.Session;
import org.hibernate.criterion.Example;

import br.com.syshealth.clinica.entity.Paciente;
//import br.com.syshealth.clinica.entity.Tipo;


@Stateless
public class PacienteDAO {

	
	private Paciente paciente;
	
	@PersistenceContext(unitName="clinica-syshealth-core")
	private EntityManager em;

	
	
	public void atualizar(Paciente bean){
		Object ent = em.merge(bean);
		System.out.println("atualizando");
		em.persist(ent);
	}
	
	public void excluir( Paciente bean) {
		Object ent = em.merge(bean);
		System.out.println("deletando");
		em.remove(ent);
	}
	
	
	
	public Paciente getBeanCpf(String cpf) {
		paciente = null;
		try{
			Query query = em.createQuery("select p from Paciente p where cpf ='"+cpf+"'");
			paciente = (Paciente) query.getSingleResult();
		}catch(Exception e){}
		return paciente;
	}
	
	
	
	public void salvar(Paciente bean) {
		if(em == null)
		{
			System.out.println("nulll");
		}else{System.out.println("aberta");
			
//			bean.setTipo(em.find(Tipo.class, bean.getTipo().getIdTipo()));
//			
//			System.out.println(bean.getTipo().getDescTipo());
//			
//			bean.getTipo().getPessoas().add(bean);		
		em.persist(bean);
		}
	}
	
	

}
